//
//  ClassifiCation.m
//  WestAir
//
//  Created by s on 16/10/5.
//  Copyright © 2016年 Henry. All rights reserved.
//

#import "ClassifiCation.h"
#import "SellingViewController.h"

@interface ClassifiCation ()<UITabBarDelegate,UITableViewDataSource>

@property(nonatomic,strong)NSMutableArray  *arrData;


@end

@implementation ClassifiCation
@synthesize arrData,mainTableView;


- (IBAction)popBack:(id)sender {
    
    
    
    [self.navigationController  popViewControllerAnimated:YES];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self  initData];
   
}

-(void)initData{
    
   
         NSDictionary  *dicJson=  [CMCCIOTIGUnity   getRequestJson:@{}];
        [[NetworkFactory  alloc]  startPostRequestWithURL:GETPRODUCTCATOGERYLIST andPostValues:dicJson andSuccessBlock:^(NSDictionary *responseJson) {
            
            
            if ([responseJson[@"IsSuccess"]  integerValue]==1) {
                
                if ([responseJson[@"data"]  isKindOfClass:[NSArray  class]]) {
                    arrData=[responseJson[@"data"]  mutableCopy];
                    
                    NSDictionary  *dicAll=@{@"FName":@"全部"};
                    [arrData insertObject:dicAll atIndex:0];
                    
                }
                else{
                    arrData=[@[]  mutableCopy];
                }
                [mainTableView  reloadData];
                
                
            }
            else{
                
                [mainTableView  reloadData];

                
            }
            
            
        } andFailBlock:^(NSError *error) {
            [mainTableView  reloadData];

            
        } ];
  
   
   

}


#pragma mark tableView  deleget

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    return arrData.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    UITableViewCell    *cell=[tableView dequeueReusableCellWithIdentifier:@"classCation"];
    if (!cell) {
        cell=[[UITableViewCell  alloc]  initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"classCation"];
    }
    
     NSDictionary  *dicTem=arrData[indexPath.row];
     cell.textLabel.text=[dicTem[@"FName"]  nullClass];
     cell.contentView.backgroundColor=[UIColor clearColor];
    cell.textLabel.font=[UIFont systemFontOfSize:14];
     cell.backgroundColor=[UIColor clearColor
                           ];
    return cell;
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 45;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    
    NSDictionary  *dicData=arrData[indexPath.row];
    
   
    [self pushToSelling:dicData];
   

}

-(void)pushToSelling:(NSDictionary  *)dicTem{
    [self.navigationController.viewControllers enumerateObjectsUsingBlock:^(__kindof UIViewController * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        UIViewController  *controller=obj;
        
        if ([controller  isKindOfClass:[SellingViewController class]]) {
            [self.navigationController  popToViewController:controller animated:YES];
        } ;
      
        
        ;
    }];

    self.classBlock(dicTem);
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
